<?php

namespace app\controller;

use app\Request;
use app\service\RoleService;

class RoleController
{

    public function getList(Request $request)
    {
        $page = $request->post('page');
        $pageSize = $request->post('pageSize');
        $result = RoleService::getInstance()->getRoleList($page, $pageSize);
        return jsonResponse($result);
    }
    public function create(Request $request)
    {
        $name = $request->post('name');
        $description = $request->post('description');
        $status = $request->post('status');

        $result = RoleService::getInstance()->createRole($name, $description, $status);
        return jsonResponse($result);
    }

    public function update(Request $request)
    {
        $id = $request->post('id');
        $name = $request->post('name');
        $description = $request->post('description');
        $status = $request->post('status');
        $result = RoleService::getInstance()->updateRole($id, $name, $description, $status);
        return jsonResponse($result);
    }

    public function delete(Request $request)
    {
        $id = $request->post('id');
        $result = RoleService::getInstance()->deleteRole($id);
        return jsonResponse($result);
    }

    public function createRoleMenus(Request $request)
    {
        $id = $request->post('id');
        $menuIds = $request->post('menu_ids');
        $result = RoleService::getInstance()->createRoleMenus($id, $menuIds);
        return jsonResponse($result);
    }

    public function getRoleMenus(Request $request)
    {
        $id = $request->post('id');
        $result = RoleService::getInstance()->getRoleMenus($id);
        return jsonResponse($result);
    }
}
